# 指定 CMake 最低版本
cmake_minimum_required(VERSION 3.20)

# 项目名称
project(cmake_property)

#[[

]]

# 全局属性
set_property(GLOBAL PROPERTY TEST_GLOBAL "test global property") # 设置全局属性
get_property(val GLOBAL PROPERTY TEST_GLOBAL) # 获取全局属性
message("TEST_GLOBAL = ${val}")

# 访问子目录中的全局属性
add_subdirectory(sub1)
get_property(val GLOBAL PROPERTY SUB1_GLOBAL) # 获取全局属性
message("SUB1_GLOBAL = ${val}")

# APPEND 数组方式拼接
set_property(GLOBAL APPEND PROPERTY TEST_APPEND "append 001")
set_property(GLOBAL APPEND PROPERTY TEST_APPEND "append 002")
set_property(GLOBAL APPEND PROPERTY TEST_APPEND "append 003")
get_property(val GLOBAL PROPERTY TEST_APPEND) # 获取全局属性
message("TEST_APPEND = ${val}")

# APPEND_STRING 字符串方式拼接
set_property(GLOBAL APPEND_STRING PROPERTY TEST_APPEND_STRING "append 001")
set_property(GLOBAL APPEND_STRING PROPERTY TEST_APPEND_STRING "append 002")
set_property(GLOBAL APPEND_STRING PROPERTY TEST_APPEND_STRING "append 003")
get_property(val GLOBAL PROPERTY TEST_APPEND_STRING) # 获取全局属性
message("TEST_APPEN_STRING = ${val}")

message("================================================================")

# 设置属性
set_property(GLOBAL PROPERTY P1 "p1")

# 判断是否被设置 -- set_property
get_property(var GLOBAL PROPERTY P1 SET) 
message("P1 SET = ${var}")
if(var)
    message("P1 is set")
else()
    message("P1 is not set")
endif()

# 判断是否被定义 define_property
get_property(var GLOBAL PROPERTY P1 DEFINED) 
message("P1 DEFINED = ${var}")

if(NOT var)
    message("P1 is not defined")
endif()

# 定义属性，不需要赋值
define_property(GLOBAL PROPERTY TEST_DEF)
get_property(var GLOBAL PROPERTY TEST_DEF DEFINED)
if(var)
    message("TEST_DEF is defined")
endif()